home *** CD-ROM | disk | FTP | other *** search
/ Freelog 22 / freelog 22.iso / Prog / Djgpp / GPC2952B.ZIP / doc / gpc / docdemos / absolutedemo.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2001-02-09  |  966 b   |  42 lines

  1. program AbsoluteDemo;
  2.  
  3. {$X+}
  4.  
  5. const
  6.   IOMem = $f0000000;
  7.  
  8. var
  9.   Mem: array [0 .. High (Cardinal)] of Byte absolute 0;
  10.  
  11.   { This address has no actual meaning }
  12.   MyPort: Byte absolute IOMem + $c030;
  13.  
  14. { Beware: Using any of the variables above will crash
  15.   your program unless you know exactly what you do!
  16.   That's why GPC warns about it without the $X+ directive. }
  17.  
  18. var
  19.   x: Real;
  20.   a: array [1 .. SizeOf (Real)] of Byte absolute x;
  21.   i: Integer;
  22.   b: Byte absolute a [i];  { GNU extension: non-constant memory reference. }
  23.  
  24. begin
  25.   x := 3.14;
  26.  
  27.   { Look at the internal representation of a real variable. }
  28.   for i := 1 to SizeOf (Real) do
  29.     Write (a [i] : 4);
  30.   WriteLn;
  31.  
  32.   { The same again, more ugly... }
  33.   for i := 1 to SizeOf (Real) do
  34.     Write (b : 4);
  35.   WriteLn;
  36.  
  37.   { And yes, there's an even more ugly way to do it... }
  38.   for i := 1 to SizeOf (Real) do
  39.     Write (Mem [PtrCard (@x) + i - 1] : 4);
  40.   WriteLn
  41. end.
  42.